/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aptech.fpt.c0810g.newspj.dataaccess;

import com.aptech.fpt.c0810g.newspj.dataaccess.share.InvokeSelectQuery;
import com.aptech.fpt.c0810g.newspj.entity.News;
import java.util.ArrayList;
import java.util.HashMap;

/**
 *
 * @author zang
 */
public class NewsListAction {

    /***
     * @author AnhGT
     * @return Danh sach tin tuc theo cate
     */
    public ArrayList<News> getNewsListByCate(int pCateID) {
        ArrayList<News> list = new ArrayList<News>();
        //Cac cot muon truy van
        ArrayList<String> colums = new ArrayList<String>();
        colums.add("ID");
        colums.add("Title");
        colums.add("SubContent");
        colums.add("Photo");
        //Cac dieu dien 
        ArrayList<String> codition = new ArrayList<String>();
        codition.add("Catelogy="+pCateID);
        //Bang muon truy van
        String tableName = "News";
        ArrayList<HashMap<String, Object>> records = new InvokeSelectQuery().getList(colums, tableName, codition);
        //add gia tri
        for (int i = 0; i < records.size(); i++) {
            News newList = new News();
            newList.setId(Integer.valueOf(records.get(i).get("ID").toString()));
            newList.setTitle(records.get(i).get("Title").toString());
            newList.setSubContent(records.get(i).get("SubContent").toString());
            newList.setPhoto(records.get(i).get("Photo").toString());
            list.add(newList);
        }
        return list;
    }
}
